package com.waitingsnow.modules.shell.view.baseView
{
import assets.shellView.MasterBottomAsset;

import com.waitingsnow.core.debug.Logger;
import com.waitingsnow.core.model.config.AppConfig;
import com.waitingsnow.core.util.ds.ExternalUtil;
import com.waitingsnow.modules.shell.model.vo.RubyServerVO;
import com.waitingsnow.modules.shell.view.baseView.events.MasterBottomViewEvent;

import flash.display.Sprite;
import flash.events.MouseEvent;

/**
 * 
 * @author waitingsnow
 * $Id: MasterBottomView.as 2 2012-05-17 10:10:03Z cgslendy@gmail.com $
 */
public class MasterBottomView extends Sprite
{
	//==========================================================================
	//  Constructor
	//==========================================================================
	/**
	 * Constructs a new <code>Application</code> instance.
	 * 
	 */
	public function MasterBottomView()
	{
		initDisplay();
	}
	
	//==========================================================================
	//  Variables
	//==========================================================================
	private var masterBottomAsset:MasterBottomAsset;
	private var rubyServerVO:RubyServerVO;
	
	//==========================================================================
	//  Methods
	//==========================================================================
	private function initDisplay():void
	{
	}
	
	private function updateTicketData(value:int):void
	{
		Logger.log("UPDATE_TICKET_TO_SWF(" + value + ")");
		masterBottomAsset.activityInfo_mc.ticket_txt.text = String(value);
		rubyServerVO.soldTicketNum = value;
	}
	
	private function updateAudienceData(value:int):void
	{
		Logger.log("UPDATE_AUDIANCE_TO_SWF(" + value + ")");
		masterBottomAsset.activityInfo_mc.audiance_txt.text = String(value);
		rubyServerVO.audienceNum = value;
	}
	
	private function updateFireWorksData(value:int):void
	{
		Logger.log("UPDATE_FIRE_WORKS_TO_SWF(" + value + ")");
		masterBottomAsset.activityInfo_mc.fireworks_txt.text = String(value);
		rubyServerVO.fireWorksNum = value;
	}
	
	private function updateIncomeData(value:int):void
	{
		Logger.log("UPDATE_INCOME_TO_SWF(" + value + ")");
		masterBottomAsset.activityInfo_mc.income_txt.text = String(value);
		rubyServerVO.totalIncome = value;
	}
	
	public function setMasterData(vo:RubyServerVO, beginFlag:Boolean):void
	{
		rubyServerVO = vo;
		if (!masterBottomAsset)
		{
			masterBottomAsset = new MasterBottomAsset();
		}
		masterBottomAsset.playControl_mc.gotoAndStop(beginFlag ? 2 : 1);
		masterBottomAsset.playControl_mc.addEventListener(MouseEvent.CLICK, playControlClickHandler);
		masterBottomAsset.set_mc.addEventListener(MouseEvent.CLICK, videoSetClickHandler);
		addChild(masterBottomAsset);
		updateTicketData(vo.soldTicketNum);
		updateAudienceData(vo.audienceNum);
		updateFireWorksData(vo.fireWorksNum);
		updateIncomeData(vo.totalIncome);
		ExternalUtil.callback(AppConfig.UPDATE_TICKET_TO_SWF, updateTicketData);
		ExternalUtil.callback(AppConfig.UPDATE_AUDIANCE_TO_SWF, updateAudienceData);
		ExternalUtil.callback(AppConfig.UPDATE_FIRE_WORKS_TO_SWF, updateFireWorksData);
		ExternalUtil.callback(AppConfig.UPDATE_INCOME_TO_SWF, updateIncomeData);
	}
	
	public function changeStatus(status:int = 2):void
	{
		masterBottomAsset.playControl_mc.gotoAndStop(status);
	}
	
	public function resize():void
	{
		if (masterBottomAsset)
		{
			masterBottomAsset.activityInfo_mc.x = AppConfig.swfWidth - masterBottomAsset.activityInfo_mc.width - 10;
			masterBottomAsset.bg_mc.width = AppConfig.swfWidth;
		}
	}
	
	public function dispose():void
	{
		mouseEnabled = mouseChildren = false;
	}
	
	//==========================================================================
	//  Event Handlers
	//==========================================================================
	private function playControlClickHandler(event:MouseEvent):void
	{
		var beginFlag:Boolean = masterBottomAsset.playControl_mc.currentFrame == 1;
		dispatchEvent(new MasterBottomViewEvent(beginFlag ? 
			MasterBottomViewEvent.START_LIVE_BTN_CLICK : MasterBottomViewEvent.END_LIVE_BTN_CLICK));
	}
	
	private function videoSetClickHandler(event:MouseEvent):void
	{
		dispatchEvent(new MasterBottomViewEvent(MasterBottomViewEvent.VIDEO_SET_CLICK_HANDLER));
	}
}
}